package com.smartwebx.ha.web.admin.module.screen.report;

import java.io.PrintWriter;
import java.util.List;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;

import com.alibaba.citrus.turbine.dataresolver.Param;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.smartwebx.ha.biz.assign.HaDirectoryManager;
import com.smartwebx.ha.biz.assign.HaReportManager;
import com.smartwebx.ha.biz.assign.HaUserManager;
import com.smartwebx.ha.dal.assign.bean.HaUser;
import com.smartwebx.ha.web.admin.common.util.HaTool;

/**
 * 
 * 创建人：Dream~天涯 
 * 创建时间：2015-5-6 下午2:57:31
 * 邮箱：154494796@qq.com
 * 备注：
 */
public class PostGetUserCode {
	@Autowired
	private HttpServletResponse response;
	@Autowired
	private HaUserManager haUserManager;
	@Autowired
	private HttpServletRequest request;
	public void execute(@Param("directoryId") String directoryId) throws Exception{
		response.setContentType("application/json");
		PrintWriter out=response.getWriter();
		ObjectMapper mapper=new ObjectMapper();
		HaUser haUser = haUserManager.findById(Integer.parseInt(directoryId.substring(1, directoryId.length())));
		Cookie[] cookies = request.getCookies();
		String code = HaTool.getCookie(request,cookies,"code");
		if(haUser.getCode().equals(code)){
			mapper.writeValue(out, "success");
		}else{
			mapper.writeValue(out, "false");
		}
	}
}
